#include <assert.h>
#include <string.h>
#include <leveldb/db.h>
#include <iostream>

int main()
{
    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options,"/tmp/testdb", &db);
    assert(status.ok());

    //write key1,value1
    std::string key="lanve";
    std::string value = "PowerAll";
    status = db->Put(leveldb::WriteOptions(), key,value);
    assert(status.ok());

    //std::string key2 = "brandbase.mama.cn:80/hinsang.php";
    std::string key2 = "lanve";
    std::string value2 = "test";
    status = db->Put(leveldb::WriteOptions(), key2,value2);
    assert(status.ok());
    
    //status = db->Put(leveldb::WriteOptions(), key2,value2);
    //assert(status.ok());
    std::string temp;
    status = db->Get(leveldb::ReadOptions(), key, &temp);
    assert(status.ok());
    std::cout<<key<<":"<<temp<<std::endl;

    //std::string key2 = "key2";
    //move the value under key to key2
    //status = db->Put(leveldb::WriteOptions(),key2,value);
    //assert(status.ok());
    //status = db->Delete(leveldb::WriteOptions(), key);
    //assert(status.ok());
    //status = db->Get(leveldb::ReadOptions(),key2, &value);
    //assert(status.ok());
    //std::cout<<key2<<"==="<<value<<std::endl;
    //status = db->Get(leveldb::ReadOptions(),key, &value);
    //if(!status.ok()) std::cerr<<key<<" "<<status.ToString()<<std::endl;
    //else std::cout<<key<<"==="<<value<<std::endl;
    //delete db;
    return 0;
}
